//create by lwy 2017年9月29日11:34:10

var page=0;
var memberNum = '';
var memberNumLength = '';
$(function () {
    doAjax();
})

function doAjax() {
    page++;
    $.ajax({
        url:'/lowerC/lookLower.json',
        dataType:'json',
        data:{
            token:getItem('token'),
            grade:GetQueryString('grade'),
            page:page,
        },
        type:'post',
        beforeSend:function(){
            if(page==1){
                $('<div class="loading"><img src="../phoneImg/jiazaizhong.gif"/></div>').appendTo($('.memberBox'));
            }
        },
        success:function (data) {
            if(data.code==1){
                memberNumLength = data.datas.data.length;
                memberNum = data.datas.data;
                if(page==1){
                    $('.memberBox').empty();
                    if(memberNumLength==0){
                        mui('#refreshContainer').pullRefresh().disablePullupToRefresh();
                        $('<div class="kong"><img src="../img/kong.png" alt="暂无数据"></div>').appendTo($('.memberBox'));
                    }
                }

                var grade = '';
                for(var i=0;i<memberNum.length;i++){
                    if(GetQueryString('grade')==1){
                        grade='一级'
                    }else if(GetQueryString('grade')==2){
                        grade='二级'
                    }else{
                        grade='三级'
                    }
                    $('<div class="member">\n' +
                        '<p><span>昵&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;称：</span><span>'+memberNum[i].realNmae+'</span></p>\n' +
                        '<p><span>账&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号：</span><span>'+memberNum[i].name+'</span></p>\n' +
                        '<p><span>级&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别：</span><span>'+grade+'</span></p>\n' +
                        '<p><span>注册时间：</span><span>'+memberNum[i].createTime+'</span></p>\n' +
                        '</div>').appendTo($('.memberBox'))
                }
            }
            if(data.code==-1){
                window.location.href="login.html"
            }
            if(data.code==0){
                mui.toast(data.msg);
                return;
            }
        }
    })
    return memberNumLength;
}

//上拉加载
mui.init({
    pullRefresh : {
        container:"#refreshContainer",//待刷新区域标识，querySelector能定位的css选择器均可，比如：id、.class等
        up : {
            contentrefresh : "正在加载...",//可选，正在加载状态时，上拉加载控件上显示的标题内容
            contentnomore:'我是有底线的',//可选，请求完毕若没有更多数据时显示的提醒内容；
            callback :function(){
                setTimeout(function () {
                    var numResult = doAjax();
                    if (numResult < 20) {
                        mui('#refreshContainer').pullRefresh().endPullupToRefresh(true);
                    } else {
                        mui('#refreshContainer').pullRefresh().endPullupToRefresh(false);
                    }
                }, 1000);
            } //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
        }
    }
});